home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kellogg's Amérique
/
Kellogg's Amérique
/
decouverte_amerique.swf
/
scripts
/
amerique
/
Decouverte_amerique.as
Wrap
Text File
|
2020-08-04
|
18KB
|
513 lines
package amerique
{
import caurina.transitions.Tweener;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.ui.Keyboard;
import flash.utils.Timer;
import flash.utils.getQualifiedClassName;
import jeux.Jeu;
public class Decouverte_amerique extends Jeu
{
public var page_accueil:MovieClip;
private var destinationX:Number = 339.5;
private const DUREE_PARTIE:Number = 1125.0;
public var chargement:MovieClip;
private var direction_droite:Boolean;
private var bonneReponse:Boolean;
public var fond:MovieClip;
private var quit:Boolean = false;
private const NOMBRE_MAX_VIES:Number = 3;
private var reponse:Number;
private var direction_gauche:Boolean;
private const ARGENT_DEPART:Number = 10;
private const NOMBRE_OBSTACLES:Number = 1;
var displayPersos:Array;
public var page_resultat:MovieClip;
private var bonChemin:Number;
private var argent:Number;
public var page_jeu:MovieClip;
private const POSITION_MIN_X:Number = -381.7;
public var titre:MovieClip;
private const INTERVALES_APPARITION_OBSTACLES:Number = 75;
private var temps:Number;
private var collision:Boolean = true;
private var gagne:Boolean;
private var vitesseX:Number = 8;
private const POSITION_MAX_X:Number = 504.5;
private var chemin:Number;
private var vitesseObstacles:Number = 10;
const COEF_SCORE:Number = 0.01;
private var nbCollision:Number;
private var question:Number;
private var obstacles:Array;
public function Decouverte_amerique()
{
var _loc1_:Number = NaN;
quit = false;
obstacles = new Array();
destinationX = 339.5;
vitesseX = 8;
displayPersos = new Array();
vitesseObstacles = 10;
collision = true;
super();
pages = [chargement,page_accueil,page_jeu,page_resultat];
hide_all_but(page_accueil);
page_accueil.btn_jouer.addEventListener(MouseEvent.CLICK,clic_bouton);
page_resultat.btn_jouer.addEventListener(MouseEvent.CLICK,clic_bouton);
_loc1_ = 1;
while(_loc1_ <= 10)
{
this.page_jeu["question_" + _loc1_].btBonne.addEventListener(MouseEvent.CLICK,bouton_bonne_reponse);
this.page_jeu["question_" + _loc1_].btMauvaise1.addEventListener(MouseEvent.CLICK,bouton_mauvaise_reponse);
this.page_jeu["question_" + _loc1_].btMauvaise2.addEventListener(MouseEvent.CLICK,bouton_mauvaise_reponse);
_loc1_++;
}
this.page_jeu.btContinuer.btBonne.addEventListener(MouseEvent.CLICK,reprendre_jeu);
this.page_jeu.btContinuer.btBonne.buttonMode = true;
this.page_jeu.btTerminer.btBonne.addEventListener(MouseEvent.CLICK,finjeu);
this.page_jeu.btTerminer.btBonne.buttonMode = true;
}
private function afficher_choix_chemin() : void
{
var _loc1_:Number = NaN;
var _loc2_:Timer = null;
this.page_jeu.choix_depart.visible = true;
this.page_jeu.choix_depart.perso.visible = true;
this.page_jeu.choix_depart.gotoAndPlay(1);
page_jeu.chemin_1.visible = false;
page_jeu.chemin_2.visible = false;
page_jeu.chemin_3.visible = false;
page_jeu.chemin_1.gotoAndStop(1);
page_jeu.chemin_2.gotoAndStop(1);
page_jeu.chemin_3.gotoAndStop(1);
_loc1_ = 1;
while(_loc1_ <= 3)
{
page_jeu["mauvaiseReponse_" + _loc1_].visible = false;
page_jeu["bonneReponse_" + _loc1_].visible = false;
_loc1_++;
}
bonChemin = Math.floor(Math.random() * 3 + 1);
_loc1_ = 1;
while(_loc1_ <= 3)
{
if(_loc1_ == bonChemin)
{
page_jeu.choix_depart["chemin_" + _loc1_].alpha = 1;
page_jeu.choix_depart["chemin_" + _loc1_].visible = true;
}
else
{
page_jeu.choix_depart["chemin_" + _loc1_].alpha = 0;
page_jeu.choix_depart["chemin_" + _loc1_].visible = false;
}
this.page_jeu.choix_depart["btChoix_" + _loc1_].visible = false;
this.page_jeu.choix_depart["bonneReponse_" + _loc1_].visible = false;
this.page_jeu.choix_depart["mauvaiseReponse_" + _loc1_].visible = false;
_loc1_++;
}
_loc1_ = 1;
while(_loc1_ <= 3)
{
this.page_jeu.choix_depart["btChoix_" + _loc1_].addEventListener(MouseEvent.CLICK,bouton_choisir_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc1_].addEventListener(MouseEvent.MOUSE_OVER,bouton_afficher_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc1_].addEventListener(MouseEvent.MOUSE_OUT,bouton_afficher_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc1_].buttonMode = true;
_loc1_++;
}
this.page_jeu.choix_depart.explications.gotoAndStop(1);
_loc2_ = new Timer(4500,1);
_loc2_.addEventListener("timer",afficher_choix_chemin_boutons);
_loc2_.start();
}
private function demarrer(param1:TimerEvent) : *
{
this.page_jeu.choix_depart.visible = false;
afficher_question();
addEventListener(Event.ENTER_FRAME,actualiser);
}
private function bouton_afficher_chemin(param1:MouseEvent) : void
{
var _loc2_:Number = NaN;
_loc2_ = param1.currentTarget.name.substr(param1.currentTarget.name.indexOf("_") + 1,param1.currentTarget.name.length - param1.currentTarget.name.indexOf("_") + 1);
switch(param1.type)
{
case MouseEvent.MOUSE_OVER:
page_jeu.choix_depart["chemin_" + _loc2_].visible = true;
page_jeu.choix_depart["chemin_" + _loc2_].alpha = 1;
break;
case MouseEvent.MOUSE_OUT:
page_jeu.choix_depart["chemin_" + _loc2_].visible = false;
page_jeu.choix_depart["chemin_" + _loc2_].alpha = 0;
}
}
private function keyDownHandler(param1:KeyboardEvent) : void
{
switch(param1.keyCode)
{
case Keyboard.LEFT:
direction_gauche = true;
break;
case Keyboard.RIGHT:
direction_droite = true;
}
}
override public function toString() : String
{
return "Jeu " + getQualifiedClassName(this);
}
override public function jouer() : *
{
trace("jouer");
hide_all_but(page_jeu);
fond.visible = false;
quit = false;
temps = 0;
page_jeu.score.score = 0;
collision = true;
nbCollision = 0;
gagne = false;
question = 0;
reponse = 0;
effacer_questions();
effacer_reponse();
page_jeu.btContinuer.visible = false;
page_jeu.btTerminer.visible = false;
argent = ARGENT_DEPART;
page_jeu.argent.texte.text = argent;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
afficher_choix_chemin();
}
private function afficher_reponse2(param1:TimerEvent = null) : *
{
if(reponse != 0)
{
reprendre_jeu();
if(question >= 10)
{
finjeu();
}
else if(argent == 0)
{
finjeu();
}
}
}
private function keyUpHandler(param1:KeyboardEvent) : void
{
switch(param1.keyCode)
{
case Keyboard.LEFT:
direction_gauche = false;
break;
case Keyboard.RIGHT:
direction_droite = false;
}
}
private function effacer_questions() : void
{
var _loc1_:Number = NaN;
_loc1_ = 1;
while(_loc1_ <= 10)
{
this.page_jeu["question_" + _loc1_].visible = false;
_loc1_++;
}
page_jeu.bonneReponse_1.visible = false;
page_jeu.mauvaiseReponse_1.visible = false;
}
public function finjeu(param1:* = null) : void
{
if(!quit)
{
trace("finjeu");
hide_all_but(page_resultat);
page_resultat.bulle_fin.bravo1.visible = false;
page_resultat.bulle_fin.bravo.visible = false;
page_resultat.bulle_fin.dommage.visible = false;
if(page_jeu.score.score >= 8)
{
page_resultat.bulle_fin.bravo1.visible = true;
page_resultat.bulle_fin.bravo1.points.text = page_jeu.score.score;
jouer_son_victoire();
}
else if(page_jeu.score.score > 4)
{
page_resultat.bulle_fin.bravo.visible = true;
page_resultat.bulle_fin.bravo.points.text = page_jeu.score.score;
jouer_son_victoire();
}
else
{
page_resultat.bulle_fin.dommage.visible = true;
page_resultat.bulle_fin.dommage.points.text = page_jeu.score.score;
if(page_jeu.score.score >= 2)
{
page_resultat.bulle_fin.dommage.textePoints.text = "points,";
}
else
{
page_resultat.bulle_fin.dommage.textePoints.text = "point,";
}
jouer_son_defaite();
}
if(fin != null)
{
fin(page_jeu.score.score);
}
fond.visible = true;
quitter();
}
}
private function bouton_mauvaise_reponse(param1:MouseEvent) : void
{
var _loc2_:Timer = null;
param1.currentTarget.mouseEnabled = false;
param1.currentTarget.buttonMode = false;
bonneReponse = false;
argent = argent - 1;
page_jeu.argent.texte.text = argent;
if(argent == 0)
{
page_jeu["question_" + question].btBonne.mouseEnabled = false;
page_jeu["question_" + question].btMauvaise1.mouseEnabled = false;
page_jeu["question_" + question].btMauvaise2.mouseEnabled = false;
page_jeu["question_" + question].btBonne.buttonMode = false;
page_jeu["question_" + question].btMauvaise1.buttonMode = false;
page_jeu["question_" + question].btMauvaise2.buttonMode = false;
_loc2_ = new Timer(2000,1);
_loc2_.addEventListener("timer",finjeu);
_loc2_.start();
}
page_jeu.mauvaiseReponse_1.x = param1.currentTarget.x + param1.currentTarget.parent.x + param1.currentTarget.width;
page_jeu.mauvaiseReponse_1.y = param1.currentTarget.y + param1.currentTarget.parent.y + 8;
page_jeu.mauvaiseReponse_1.visible = true;
}
private function afficher_reponse(param1:Number = 0) : *
{
var _loc2_:Number = NaN;
reponse = param1;
_loc2_ = 1;
while(_loc2_ <= 10)
{
this.page_jeu["reponse_" + _loc2_].visible = _loc2_ == reponse;
_loc2_++;
}
if(question >= 10)
{
}
}
private function bouton_choisir_chemin(param1:MouseEvent) : void
{
var _loc2_:Number = NaN;
var _loc3_:Number = NaN;
var _loc4_:Timer = null;
_loc2_ = param1.currentTarget.name.substr(param1.currentTarget.name.indexOf("_") + 1,param1.currentTarget.name.length - param1.currentTarget.name.indexOf("_") + 1);
chemin = _loc2_;
this.page_jeu.choix_depart.perso.visible = false;
page_jeu["chemin_" + chemin].visible = true;
if(bonChemin == _loc2_)
{
this.page_jeu.choix_depart.explications.gotoAndStop(3);
this.page_jeu.choix_depart["bonneReponse_" + _loc2_].visible = true;
argent += 2;
page_jeu.argent.texte.text = argent;
}
else
{
this.page_jeu.choix_depart.explications.gotoAndStop(4);
this.page_jeu.choix_depart["mauvaiseReponse_" + _loc2_].visible = true;
argent -= 2;
page_jeu.argent.texte.text = argent;
}
_loc3_ = 1;
while(_loc3_ <= 3)
{
this.page_jeu.choix_depart["btChoix_" + _loc3_].removeEventListener(MouseEvent.CLICK,bouton_choisir_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc3_].removeEventListener(MouseEvent.MOUSE_OVER,bouton_afficher_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc3_].removeEventListener(MouseEvent.MOUSE_OUT,bouton_afficher_chemin);
this.page_jeu.choix_depart["btChoix_" + _loc3_].buttonMode = false;
_loc3_++;
}
(_loc4_ = new Timer(2000,1)).addEventListener("timer",demarrer);
_loc4_.start();
}
private function afficher_choix_chemin_boutons(param1:TimerEvent) : *
{
var _loc2_:Number = NaN;
_loc2_ = 1;
while(_loc2_ <= 3)
{
Tweener.addTween(page_jeu.choix_depart["chemin_" + _loc2_],{
"alpha":0,
"time":1,
"transition":"linear",
"onComplete":afficher_choix_chemin_boutons2
});
_loc2_++;
}
}
public function afficher_question() : void
{
var _loc1_:Number = NaN;
bonneReponse = true;
page_jeu["chemin_" + chemin].stop();
++question;
_loc1_ = 1;
while(_loc1_ <= 10)
{
if(_loc1_ == question)
{
page_jeu["question_" + _loc1_].visible = true;
page_jeu["question_" + _loc1_].btBonne.mouseEnabled = true;
page_jeu["question_" + _loc1_].btMauvaise1.mouseEnabled = true;
page_jeu["question_" + _loc1_].btMauvaise2.mouseEnabled = true;
page_jeu["question_" + _loc1_].btBonne.buttonMode = true;
page_jeu["question_" + _loc1_].btMauvaise1.buttonMode = true;
page_jeu["question_" + _loc1_].btMauvaise2.buttonMode = true;
}
else
{
page_jeu["question_" + _loc1_].visible = false;
}
_loc1_++;
}
}
private function effacer_reponse(param1:TimerEvent = null) : *
{
var _loc2_:Number = NaN;
_loc2_ = 1;
while(_loc2_ <= 10)
{
this.page_jeu["reponse_" + _loc2_].visible = false;
_loc2_++;
}
}
private function reprendre_jeu(param1:MouseEvent = null) : void
{
effacer_questions();
effacer_reponse();
page_jeu.btContinuer.visible = false;
page_jeu.btTerminer.visible = false;
page_jeu["chemin_" + chemin].play();
}
override public function quitter() : *
{
removeEventListener(Event.ENTER_FRAME,actualiser);
quit = true;
}
private function bouton_bonne_reponse(param1:MouseEvent) : void
{
page_jeu["question_" + question].btBonne.mouseEnabled = false;
page_jeu["question_" + question].btMauvaise1.mouseEnabled = false;
page_jeu["question_" + question].btMauvaise2.mouseEnabled = false;
page_jeu["question_" + question].btBonne.buttonMode = false;
page_jeu["question_" + question].btMauvaise1.buttonMode = false;
page_jeu["question_" + question].btMauvaise2.buttonMode = false;
if(bonneReponse)
{
page_jeu.score.score += 1;
}
afficher_reponse(question);
page_jeu.bonneReponse_1.x = param1.currentTarget.x + param1.currentTarget.parent.x + param1.currentTarget.width;
page_jeu.bonneReponse_1.y = param1.currentTarget.y + param1.currentTarget.parent.y;
page_jeu.bonneReponse_1.visible = true;
if(question < 10)
{
page_jeu.btContinuer.visible = true;
}
else
{
page_jeu.btTerminer.visible = true;
}
}
private function actualiser(param1:Event) : void
{
var _loc2_:Number = NaN;
var _loc3_:String = null;
_loc3_ = page_jeu["chemin_" + chemin].currentLabel;
if(_loc3_ != null)
{
_loc2_ = Number(_loc3_.substr(_loc3_.indexOf("_") + 1,_loc3_.length - _loc3_.indexOf("_") + 1));
if(_loc2_ > question)
{
afficher_question();
}
}
}
private function afficher_choix_chemin_boutons2() : *
{
var _loc1_:Number = NaN;
this.page_jeu.choix_depart.explications.gotoAndStop(2);
_loc1_ = 1;
while(_loc1_ <= 3)
{
this.page_jeu.choix_depart["btChoix_" + _loc1_].visible = true;
_loc1_++;
}
}
}
}